// pages/text_ocr/text_ocr.js
Page({
  /**
   * 页面的初始数据
   */
  data: {
    showBtn:false    
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.ctx = wx.createCameraContext()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {
   
  },
  takePhoto() {
    this.ctx.takePhoto({
      quality: 'high',
      success: (res) => {       
        // {
        //   errMsg: "operateCamera:ok"
        //   height: 900
        //   tempImagePath: "wxfile://tmp_358cec635dfaa35fdec55674f447a0cbef24ea9932a1f48e.jpg"
        //   width: 1080
        // }     

        this.setData({
          showBtn:true,
          src: res.tempImagePath
        })
      }
    })
  },
  getAlubm(){
    let that = this
    wx.chooseMedia({
      count: 5,
      success(res) {
        //此处会返回图片暂存路径和文件大小
        const data = res.tempFiles[0].tempFilePath

        wx.getImageInfo({
          src: data,
          success:(res)=>{
            let image_info = res
            let image_width = res.width
            let image_height = res.height
            let compress_width = image_width

            if(image_width >= 800){
              compress_width = 800
            }

            wx.compressImage({
              src: data,
              compressedWidth:compress_width,
              quality:80,
              success:(res)=>{
                wx.getImageInfo({
                  src: res.tempFilePath,
                  success:(res)=>{
               
                  }
                })
    
                wx.getFileInfo({
                  filePath:  res.tempFilePath,
                  success:(res)=>{
                  
                  }
                })
    
                that.setData({
                  showBtn:true,
                  src: res.tempFilePath
                })
              }
            })
          }
        })       
      }
    })
  },
  textOCR(){
    let that = this
    wx.uploadFile({
      //url: 'http://121.37.180.71:8002/myocr', 
      url: 'https://admin.yzqysoft.com:8002/myocr', 
      filePath: that.data.src,
      name: 'file',
      formData:{
        'user': 'test'
      },
      success: function(res){
        var data = res.data
        //do something
      }
    })
  },
  startRecord() {
    this.ctx.startRecord({
      success: (res) => {
        console.log('startRecord')
      }
    })
  },
  stopRecord() {
    this.ctx.stopRecord({
      success: (res) => {
        this.setData({
          src: res.tempThumbPath,
          videoSrc: res.tempVideoPath
        })
      }
    })
  },
  error(e) {
    console.log(e.detail)
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})